﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuantitativeInvestment.Bean;
using QuantitativeInvestment.Tools;

namespace QuantitativeInvestment.Factor
{
    class SarFactor:Factor
    {
        public SarFactor()
        {
            this.name = "抛物线";
            Parameter p1 = new Parameter("天数",30);
            this.paraList.Add(p1.name,p1);

            Parameter p2 = new Parameter("加速度", 0.02);
            this.paraList.Add(p2.name, p2);

            Parameter p3 = new Parameter("最大值", 2);
            this.paraList.Add(p3.name, p3);
        }
        public override void addFactorValue(Stock stock)
        {
            int num = Int32.Parse(this.paraList["天数"].value.ToString());
            double optInAcceleration = Double.Parse(this.paraList["加速度"].value.ToString());
            double optInMaximum = Double.Parse(this.paraList["最大值"].value.ToString());

            if (!stock.factors.ContainsKey(this.name + this.paraList["天数"].value.ToString()))
            {
                TaLib lib = new TaLib();

                double[] sarValues = lib.getSar(stock.factors["最高价"], stock.factors["最底价"], optInAcceleration, optInMaximum);
                int length=stock.factors["最高价"].Length;

                stock.factors.Add(this.name + this.paraList["天数"].value.ToString()+"Sar:", sarValues);

            }
        }
    }
}
